// 当使用redux-thunk之后，createActions就可以返回函数了，否则只能返回对象
import {CHANGE_INPUT_VALUE, ADD_TODO_ITEM, DELETE_TODO_ITEM, INIT_STATE} from './actionTypes';
import axios from 'axios';

export const getInputChangeAction = (value) => ({
  type: CHANGE_INPUT_VALUE,
  value
})

export const getTodoAddAction = () => ({
  type: ADD_TODO_ITEM
})

export const getTodoDelAction = (index) => ({
  type: DELETE_TODO_ITEM,
  index
})

export const getInitAction = (data) => ({
  type: INIT_STATE,
  data
})

export const getTodoList = () => {
  return (dispatch) => {
    axios.get('/list.json')
      .then((res) => {
        console.log(res.data);
        const action = getInitAction(res.data);
        dispatch(action);
      });
  }
}